/*
 * Created on Apr 19, 2005
 */
package org.vectrics.recruiter.job;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.log4j.Logger;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.skill.Skill;
import org.vectrics.skill.SkillRating;
import org.vectrics.skill.SkillRatingSet;
import org.vectrics.user.Person;

/**
 * @author MMoore
 */
public class JobCandidateSkillCalculation {
	private transient Logger log = Logger.getLogger(this.getClass());
	private Job job = null;
	private JobSkillRatingSet jobSkillRatingSet = null;
	private Set setOfJobCandidateSkills = new HashSet();
	private Person person = null;
	private SkillRatingSet userSkillSet = null;
	
	public JobCandidateSkillCalculation(Person person, Job job, JobSkillRatingSet jobSkillRatingSet) {
		super();
		this.job = job;
		this.jobSkillRatingSet = jobSkillRatingSet;
		this.person = person;
		this.userSkillSet = RecruitServiceLocator.getSkillProvider().findLatestUserSkillSet(person);
	}

	public SkillRatingSet getUserSkillSet() {
		return(this.userSkillSet);
	}
	
	public JobCandidateSkill addJobCandidateSkill(JobSkillRating jobRating) {
		JobCandidateSkill jobCandidateSkill = new JobCandidateSkill();
		this.setOfJobCandidateSkills.add(jobCandidateSkill);
		jobCandidateSkill.setJobRating(jobRating);
		Skill skill = jobRating.getSkill();
		jobCandidateSkill.setScore(0);
		if (skill != null) {
			SkillRating userSkillRating = userSkillSet.findSkillRating(skill);
			jobCandidateSkill.setUserSkillRating(userSkillRating);
			if (userSkillRating != null) {
				long userScore = userSkillRating.getScore();
				jobCandidateSkill.setScore(userScore);
			}
		} else {
			
		}
		return(jobCandidateSkill);
	}
	
	public JobCandidateSkill findJobCandidateSkill(JobSkillRating jobSkillRating) {
		JobCandidateSkill found = null;
		Iterator iter = this.setOfJobCandidateSkills.iterator();
		while ((iter.hasNext()) && (found == null)) {
			JobCandidateSkill jobCandidateSkill = (JobCandidateSkill)iter.next();
			if (jobCandidateSkill.getJobRating().getId().equals(jobSkillRating.getId())) {
				found = jobCandidateSkill;
			}
		}
		return(found);
	}
	

	
}
